//
//  XLAccountSafeAdapter.m
//  industry
//
//  Created by xl on 2020/12/9.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLAccountSafeAdapter.h"
#import "XLTitleInfoArrowLineCell.h"
#import "NSString+XL.h"

NSString *const XLAccountSafeAdapterModifyPS = @"XLAccountSafeAdapterModifyPS";//修改密码
NSString *const XLAccountSafeAdapterUnlockSettrings = @"XLAccountSafeAdapterUnlockSettrings";//解锁设置
NSString *const XLAccountSafeAdapterClearData = @"XLAccountSafeAdapterClearData";//清空缓存

@implementation XLAccountSafeAdapter

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.getAdapterArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 64.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return [UITableViewCell new];
    }
    id data = self.getAdapterArray[indexPath.row];
    static NSString *cellIdentifierId = @"XLTitleInfoArrowLineCell";
    XLTitleInfoArrowLineCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierId];
    if (!cell) {
        cell = [[XLTitleInfoArrowLineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierId];
    }
    if ([data isEqualToString:XLAccountSafeAdapterModifyPS]) {
        [cell loadCellData:@"修改密码" info:@""];
    } else if ([data isEqualToString:XLAccountSafeAdapterClearData]) {
        
        [cell loadCellData:@"清空数据" info:[NSString stringWithFormat:@"%.2fMB",[self countAppletSize]]];
    } else if ([data isEqualToString:XLAccountSafeAdapterUnlockSettrings]) {
        [cell loadCellData:@"解锁设置" info:@"设置刷脸、指纹和解锁密码保护隐私"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    id cellData = self.getAdapterArray[indexPath.row];
    
    if (self.adapterDelegate && [self.adapterDelegate respondsToSelector:@selector(didSelectCellData:)]) {
        [self.adapterDelegate didSelectCellData:cellData];
    }
}

- (float)countAppletSize{
    
    
    NSString * str = [NSString stringWithFormat:@"%@/NAMAPP_UNZIP", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
    long long size = [str fileSize];
    float aa = (float)size/1000000.0;
    return aa;

}

@end
